package com.bonc.rms.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.bonc.rms.service.OrderService;

@RestController
@RequestMapping(value="orderController")
public class OrderController {
	@Autowired
	OrderService orderService;
	
	/*
	 * 显示全部订单信息
	 */
	@RequestMapping(value = "/getOrderInfo")
	@ResponseBody
	public String getOrderInfo() {
		
		List<Map<String, Object>> orderInfo = orderService.getOrderInfo();
		
		return JSON.toJSONString(orderInfo);
	}
	
	/*
	 * 查看单个订单信息
	 */
	@RequestMapping(value = "/getSingleOrderInfo")
	@ResponseBody
	public String getSingleOrderInfo(@RequestParam(value = "orderId") Integer orderId) {
		
		List<Map<String, Object>> orderInfo = orderService.getSingleOrderInfo(orderId);
		
		return JSON.toJSONString(orderInfo);
	}

	/*
	 * 修改订单信息
	 */
	@RequestMapping(value = "/updateOrderInfo")
	@ResponseBody
	public String updateOrderInfo(@RequestParam(value = "orderId") Integer orderId,
			@RequestParam(value = "userId") Integer userId,
			@RequestParam(value = "petName") String petName,
			@RequestParam(value = "orderCode") String orderCode,
			@RequestParam(value = "itemName") String itemName,
			@RequestParam(value = "quantity") String quantity,
			@RequestParam(value = "itemPricing") String itemPricing,
			@RequestParam(value = "address") String address) {
		System.out.println("in 111");
		List<Map<String, Object>> orderInfo = orderService.updateOrderInfo(orderId,userId,petName,orderCode,itemName,quantity,itemPricing,address);
		
		return JSON.toJSONString(orderInfo);
	}
	
	/*
	 * 删除订单信息
	 */
	@RequestMapping(value = "/deleteOrderInfo")
	@ResponseBody
	public String deleteOrderInfo(@RequestParam(value = "orderId") Integer orderId) {
		
		orderService.deleteOrderInfo(orderId);
		
		Map<Object,Integer> map = new HashMap<>();
		map.put("status", 200);
		return JSON.toJSONString(map);
	}

}
